package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Advice {
    @Pointcut("execution(* com.itheima.service.StudentService.*(..))")
    public void pt(){}
    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp){
        Object value = null;
        try {
            long start = System.currentTimeMillis();
            value = pjp.proceed();
            long end = System.currentTimeMillis();
            String name = pjp.getSignature().getName();
            System.out.println("执行"+name+"方法共耗时："+(end-start)+"毫秒");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return value;
    }
}
